home *** CD-ROM | disk | FTP | other *** search
- /*
- File: File.c
-
- Contains: This is the FCB dcmd.
-
- Written by: JM3 = Jim Murphy
- DAL = Dave Lyons
- sad = Scott Douglas
-
- Copyright: © 1988,1993-1995 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <7> 4/18/95 DAL Omit some boring fields from the "file 0" display (for logs).
- <6> 2/21/95 DAL Made "file 0" show all open files except for fonts (to help
- shrink Standard Logs). Bumped version to 3.0.1.
- <5> 10-Dec-94 JM3 Updated for new format 3 dcmd requirements.
- <4> 5/13/94 DAL Deal with carriage returns inside filenames (changed put.c).
- <3> 24-Jan-94 JM3 With the Universal Interfaces, EqualString is now in
- TextUtils.h. Blah.
- <2> 9/13/93 DAL made some columns wider and fixed the filename-prefix feature to
- work again
-
- Modification history:
- 29Nov88 sad revised for new dcmd names.
- 5Oct88 sad broke out formatting routines to put.c
- 30Sep88 sad written
-
- The following MPW commands will build the dcmd and copy it to the
- "Debugger Prefs" file in the System folder. The dcmd's name in
- MacsBug will be the name of the file built by the Linker.
- You must first copy dcmd.h, dcmdGlue.a.o and DRunTime.o from the
- C Samples folder into this folder.
-
- C Put.c
- C File.c
- Link dcmdGlue.a.o File.c.o put.c.o DRuntime.o "{Libraries}"Interface.o -o File
- BuildDcmd File 1003
- Echo 'include "File";' | Rez -a -o "{systemFolder}Debugger Prefs"
- */
-
- #include <Types.h>
- #include <Memory.h>
- #include <Files.h>
- #include <OSUtils.h>
- #include <TextUtils.h>
-
- #include "dcmd.h"
- #include "put.h"
-
- #define FSFCBLen 0x3f6
- #define FCBsPtr 0x34e
-
-
- typedef struct FCB
- {
- unsigned long fcbFlNum;
- unsigned char fcbMdRByt;
- unsigned char fcbTypByt;
- unsigned short fcbSBlk;
- unsigned long fcbEOF;
- unsigned long fcbPLen;
- unsigned long fcbCrPs;
- VCB* fcbVPtr;
- void* fcbBfAdr;
- unsigned short fcbFlPos;
- unsigned long fcbClmpSize;
- void* fcbBTCBPtr;
- unsigned long fcbExtRec[3];
- OSType fcbFType;
- unsigned long fcbCatPos;
- unsigned long fcbDirID;
- char fcbCName[32];
- }
- FCB;
-
-
- static void DrawHdr(Boolean shortForm)
- {
- // 1 2 3 4 5 6 7
- // 1234567890123456789012345678901234567890123456789012345678901234567890
-
- if (shortForm)
- dcmdDrawLine("\pfRef File Vol Type Fl Fork LEof");
- else
- dcmdDrawLine("\pfRef File Vol Type Fl Fork LEof Mark FlNum Parent FCB at");
- }
-
-
- static Boolean IsFontFile(FCB *fcbp)
- {
- OSType filetype = fcbp->fcbFType;
-
- if (filetype == 'FFIL' || filetype == 'ffil' || filetype == 'tfil')
- return true;
-
- return false;
- }
-
-
- static void DrawFCB(int fref, FCB* fcbp, Boolean shortForm)
- {
- PutUHexWord(fref);
- PutSpace();
- PutPStrTruncTo(fcbp->fcbCName, 17+10);
- PutSpace();
- PutPStrTruncTo(fcbp->fcbVPtr->vcbVN, 26+10+3);
- PutSpace();
- PutOSType(fcbp->fcbFType);
- PutSpace();
- PutChar((fcbp->fcbMdRByt & 0x80) ? 'D' : 'd');
- PutChar((fcbp->fcbMdRByt & 0x01) ? 'W' : 'w');
- PutSpace();
- if (fcbp->fcbMdRByt & 0x02)
- PutPStr("\prsrc ");
- else
- PutPStr("\pdata ");
- PutUDecTo(fcbp->fcbEOF,47+11+3);
-
- if (!shortForm)
- {
- PutSpace();
- PutUDecTo(fcbp->fcbCrPs,55+12+3);
- PutSpace();
- PutUHexZTo(fcbp->fcbFlNum,6,62+12+3);
- PutSpace();
- PutUHexZTo(fcbp->fcbDirID,6,69+12+3);
- PutSpace();
- PutUHexZTo((unsigned long)fcbp,6,76+12+3);
- }
-
- PutLine();
- }
-
-
- // PrefixPStr
- // returns true if astr is equal to a prefix of bstr.
- // (astr must not be longer than 31 characters)
-
- static Boolean PrefixPStr(const Str255 astr, const Str255 bstr)
- {
- char newstr[31];
- int alen = *astr;
- int blen = *bstr;
-
- if (alen <= blen)
- {
- BlockMoveData(bstr+1, newstr+1, alen);
- newstr[0] = alen;
- return EqualString(astr, newstr, false, true);
- }
- else
- return false;
- }
-
-
-
- pascal void CommandEntry(dcmdBlock* paramPtr)
- {
- static const char usageStr[] = "\p[fRefNum|\"file name\"]";
-
- switch (paramPtr->request)
- {
- case dcmdInit:
- break;
-
- case dcmdHelp:
- dcmdDrawLine("\pDisplays file information on all open files, or for the given fRefNum");
- dcmdDrawLine("\por filename. Flags are D/d=Dirty, W/w=writeable. \"file 0\" shows all");
- dcmdDrawLine("\popen files except for fonts.");
- break;
-
- case dcmdGetInfo:
- * (long *) &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->dcmdVersion = 0x03018000; // version 3.0.1 final
- BlockMoveData(&usageStr, &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->usageStr, usageStr[0]+1);
- break;
-
- case dcmdDoIt:
- {
- Boolean doOneFCB = false;
- long fref;
- short c;
- Boolean haveFileName = false;
- Str255 filename;
- int fcbLen; // the length of one fcb
- char* fcbsbase;
- int fcbslen; // the length of the fcbs block
-
- dcmdSwapWorlds();
-
- dcmdDrawLine("\pDisplaying File Control Blocks");
-
- // get low-memory values after dcmdSwapWorlds()
- fcbLen = * (unsigned short *) FSFCBLen;
- fcbsbase = * (char **) FCBsPtr;
- fcbslen = * (unsigned short *) fcbsbase;
-
- if (fcbLen != sizeof(FCB))
- {
- PutPStr("\FSFCBLen = ");
- PutUDec(fcbLen);
- PutPStr("\p expected ");
- PutUDec(fcbLen);
- PutLine(sizeof(FCB));
- }
- if ((fcbslen - 2) % fcbLen != 0)
- {
- PutPStr("\pBad fcbslen ");
- PutUHexWord(fcbslen);
- PutLine();
- }
-
- c = dcmdPeekAtNextChar();
- if (c == '"' || c == '\'')
- {
- haveFileName = true;
- (void) dcmdGetNextParameter(filename);
- }
- else
- (void) dcmdGetNextExpression(&fref, &doOneFCB);
-
- if (doOneFCB && fref)
- {
- fref = (unsigned short) fref;
- if ((fref > fcbslen) || ((fref - 2) % fcbLen != 0))
- {
- PutPStr("\pBad file refnum ");
- PutUHexWord(fref);
- PutLine();
- }
- else
- {
- FCB* fcbp = (FCB*)(fref + fcbsbase);
- if (fcbp->fcbFlNum)
- {
- DrawHdr(false /* long form */);
- DrawFCB(fref, fcbp, false /* long form */);
- }
- else
- {
- PutPStr("\pFCB ");
- PutUHexWord(fref);
- PutPStr("\p is not in use");
- PutLine();
- }
- }
- }
- else // there was no refnum on the command line (or it was 0)
- {
- int numFCBs = (fcbslen - 2) / fcbLen;
- int fcbsUsed = 0;
- int numFontsSkipped = 0;
- Boolean foundOne = false;
-
- for (fref = 2; (fref < fcbslen) && (!paramPtr->aborted); fref += fcbLen)
- {
- FCB* fcbp = (FCB *) (fcbsbase + fref);
-
- if (fcbp->fcbFlNum && (!haveFileName || PrefixPStr(filename,fcbp->fcbCName)))
- {
- fcbsUsed++;
- if (!foundOne)
- {
- DrawHdr(doOneFCB); // true = short form ("file 0")
- foundOne = true;
- }
-
- if (doOneFCB && IsFontFile(fcbp))
- numFontsSkipped++;
- else
- DrawFCB(fref, fcbp, doOneFCB /* true for short form */);
- }
- }
-
- if (!paramPtr->aborted)
- {
- if (haveFileName)
- {
- if (!foundOne)
- {
- PutPStr("\pNo open files match \"");
- PutPStr(filename);
- PutChar('"');
- PutLine();
- }
- }
- else
- {
- PutUDec(numFCBs);
- PutPStr("\p FCBs, ");
- PutUDec(fcbsUsed);
- PutPStr("\p in use");
-
- if (numFontsSkipped)
- {
- PutPStr("\p (including ");
- PutUDec(numFontsSkipped);
- PutPStr("\p fonts not listed)");
- }
- PutPStr("\p, ");
-
- PutUDec(numFCBs - fcbsUsed);
- PutPStr("\p free");
- PutLine();
- }
- }
- }
-
- dcmdSwapWorlds();
- break;
- }
-
- // Format 3 and newer dcmds must quietly ignore requests we don't recognize.
-
- default:
- break;
- }
- }
-